package com.davies.learn.jbv;

import okhttp3.OkHttpClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.net.http.HttpClient;
import java.time.Duration;

/**
 * @author davies
 * @date 2023/7/20 09:34
 */
@SpringBootApplication
public class BeanValidationApplication {


    @Bean
    public HttpClient httpClient(){

        return HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1)
                .connectTimeout(Duration.ofSeconds(6))
                .build();

    }


//    @Bean
//    public WebClient webClient(){
//
//        HttpClient httpClient = HttpClient.create();
//        httpClient.responseTimeout(Duration.ofSeconds(6));
//        httpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3 * 1000);
//        return WebClient.builder().clientConnector(new ReactorClientHttpConnector(httpClient))
//                .build();
//    }

    @Bean
    public OkHttpClient okHttpClient(){
        OkHttpClient client = new OkHttpClient();
        client.dispatcher().setMaxRequests(2000);
        client.dispatcher().setMaxRequestsPerHost(2000);
        return client;

    }



    public static void main(String[] args) {
        SpringApplication.run(BeanValidationApplication.class, args);
    }

}
